﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Customers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            display();
        }
    }
    protected void DisplayOne_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql1 = "select usr_infor.id,usr_infor.name,usr_infor.sex,usr_infor.idcard,usr_login.usr_pad,usr_login.usr_phone,usr_login.usr_phone,usr_login.usr_email,usr_infor.amount from usr_infor, usr_login where usr_infor.id = usr_login.usr_id and usr_infor.id='" + TextBox1.Text.Trim() + "' ";
            SqlDataAdapter sda1 = new SqlDataAdapter(sql1, sqlhelper.conn);
            DataSet ds1 = new DataSet();
            sda1.Fill(ds1);
            GridView1.DataSource = ds1;
            GridView1.DataBind();
        }
        catch
        {
            Response.Write("<script>alert('查找失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }

    protected void DisplayAll_Click(object sender, EventArgs e)
    {
        try
        {
            display();
        }
        catch
        {
            Response.Write("<script>alert('查找失败，请查看相关代码！')</script>");
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView1.PageSize = int.Parse(DropDownList1.SelectedValue);
        GridView1.DataBind();
        display();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        display();
    }

    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        Label1.Text = "当前页为第" + (GridView1.PageIndex).ToString() + "页，共有" + (GridView1.PageCount).ToString() + "页";
    }
    protected void display()
    {
        try
        {
            sqlhelper.conn.Open();
            string sql = "select usr_infor.id,usr_infor.name,usr_infor.sex,usr_infor.idcard,usr_login.usr_pad,usr_login.usr_phone,usr_login.usr_phone,usr_login.usr_email,usr_infor.amount from usr_infor, usr_login where usr_infor.id = usr_login.usr_id ";
            SqlDataAdapter sda = new SqlDataAdapter(sql, sqlhelper.conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        catch
        {
            Response.Write("<script>alert('查找失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }
}